    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Kết quả tìm kiếm</title>       
		 <link href="/htqlmba/libraries/css/capnhatdv.css" type="text/css" rel="stylesheet">
    </head>

    <body>
        <?php
        include_once($_SERVER['DOCUMENT_ROOT'] . "/htqlmba/ketnoiCSDL.php");
		require_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/libraries/PHPExcel_1.7.9_doc/Classes/PHPExcel.php');
		ob_start();
		session_start();
		$_SESSION["N0"] = $_GET['sono'];
		
        ?>
		
        <form name="kqtimN0" method="POST" >
 
            <?php
			 
                    $sql = "";
                    if ($_SESSION['nmaquyen'] == 3) {
                        $sql.= "select * from may_bien_ap a, chi_tiet_so_huu b where a.SO_N0=b.SO_N0 and a.SO_N0='" .$_GET['sono']. "' and MA_DON_VI=" . $_SESSION['nmadv'] . " and NGAY_CHUYEN_DEN=(select max(NGAY_CHUYEN_DEN) from chi_tiet_so_huu where SO_N0='" .$_GET['sono']. "') ";
                    } else {
                        $sql.="select * from may_bien_ap where SO_N0='" .$_GET['sono'] . "'";
                    }
                    $result = mysql_query($sql, $link);

                    if (mysql_num_rows($result) != 0) {
                      
                    } else {
                          header('Location: /htqlmba/search/kocokq.php');
                    }
              
			
            $sql = "select * from may_bien_ap a,loai_dien_ap b,nha_sx c
	where a.MA_DIEN_AP=b.MA_DIEN_AP and a.MA_NSX=c.MA_NSX and a.SO_N0='";
            $sql.=$_GET['sono'] . "'";
            $result = mysql_query($sql, $link);
            ?>

            <p align="center" class="error style9">THÔNG TIN CƠ BẢN
    <table class='table table-condensed' width="1328" height="188" border="0" cellpadding="0" cellspacing="1">
                    <tr>
                        <td width="39" height="66" class="TableHeader"><div align="center" class="style7">Số N0</div></td>
                        <td width="57" class="TableHeader"><div align="center" class="style7">MSTS</div></td>
                        <td width="58" class="TableHeader"><div align="center" class="style7">Loại điện áp (U)</div></td>
                        <td width="77" class="TableHeader"><div align="center" class="style7">Công suất (KVA)</div></td>
                        <td width="72" class="TableHeader"><div align="center" class="style7">Chiều dài<br />
                                (mm)</div></td>
                        <td width="89" class="TableHeader"><div align="center" class="style8"><span class="style8">Chiều rộng<br />
                                        (mm)</span></div></td>
                        <td width="81" class="TableHeader style8"><div align="center" class="style8">Chiều cao (mm) </div>
                            <div align="center"></div></td>
                        <td width="69" class="TableHeader"><div align="center" class="style8">Đầu máy<br />
                                    (kg)</div></td>
                        <td width="79" class="TableHeader"><div align="center" class="style8">Ruột máy<br />
                                    (kg)</div></td>
                        <td width="61" class="TableHeader"><div align="center" class="style8">Tổng<br />
                                    (kg)</div></td>
                        <td width="67" class="TableHeader"><div align="center" class="style8">Hãng <br />
                                    sản xuất</div></td>
                        <td width="78" class="TableHeader"><div align="center" class="style8">Nước <br />
                                    sản xuất</div></td>
                        <td width="71" height="66" class="TableHeader"><div align="center" class="style8">Loại dầu </div></td>
                        <td width="79" height="66" class="TableHeader"><div align="center" class="style8">Thông số đo </div></td>
                        <td width="83" height="66" class="TableHeader"><div align="center" class="style8">Nhận xét </div></td>
                        <td width="168" class="TableHeader"><div align="center" class="style8">Ghi chú</div></td>
                    </tr>

                    <?php
                    if (mysql_num_rows($result) != 0) {
                        $stt = 0;
                        while ($row = mysql_fetch_array($result)) {
                            $c1 = $row["SO_N0"];
                            $c14 = $row["MSTS"];
                            $c2 = $row["CAP_DIEN_AP"];
                            $c3 = $row["CONG_SUAT"];
                            $c4 = $row["CHIEU_DAI"];
                            $c5 = $row["CHIEU_RONG"];
                            $c6 = $row["CHIEU_CAO"];
                            $c7 = $row["DAU_MAY"];
                            $c8 = $row["RUOT_MAY"];
                            $c9 = $row["TONG"];
                            $c10 = $row["TEN_NSX"];
                            $c11 = $row["TEN_NUOC"];
                            $c12 = $row["TEN_LOAI_DAU"];
                            $c13 = $row["THONG_SO_DO"];
                            $c15 = $row["NHAN_XET"];
                            $c16 = $row["GHI_CHU"];
                            $stt++;
                            $tbcolor = "TableField";
                            if ($stt % 2 == 0) {
                                $tbcolor = "TableField2";
                            }


                            echo "<tr><td class='" . $tbcolor . "'>$c1</td>";
                            echo "<td class='" . $tbcolor . "'>$c14</td>";
                            echo "<td class='" . $tbcolor . "'>$c2</td>";
                            echo "<td class='" . $tbcolor . "'>$c3</td>";
                            echo "<td class='" . $tbcolor . "'>$c4</td>";
                            echo "<td class='" . $tbcolor . "'>$c5</td>";
                            echo "<td class='" . $tbcolor . "'>$c6</td>";
                            echo "<td class='" . $tbcolor . "'>$c7</td>";
                            echo "<td class='" . $tbcolor . "'>$c8</td>";
                            echo "<td class='" . $tbcolor . "'>$c9</td>";
                            echo "<td class='" . $tbcolor . "'>$c10</td>";
                            echo "<td class='" . $tbcolor . "'>$c11</td>";
                            echo "<td class='" . $tbcolor . "'>$c12</td>";
                            echo "<td class='" . $tbcolor . "'>$c13</td>";
                            echo "<td class='" . $tbcolor . "'>$c15</td>";
                            echo "<td class='" . $tbcolor . "'>$c16</td>";
                        }
                    }
                    ?>
    </table>
                <p></p>

            </p>
            <p align="center" class="style1"><span class="style9"><font clor="red"><font color="red">LỊCH SỬ MBA</font></span> </p>

            <?php
            $sql = "select * from may_bien_ap a
	where  a.SO_N0='";
            $sql.=$_GET['sono'] . "'";
            $result = mysql_query($sql, $link);
            ?>
            <p align="left"><strong>N&#259;m s&#7843;n xu&#7845;t:
                    <label></label>
                </strong>&nbsp;&nbsp;
                <?php
                if (mysql_num_rows($result) != 0) {
                    $stt = 0;
                    while ($row = mysql_fetch_array($result)) {
                        $stt++;
                        $tbcolor = "TableField";
                        if ($stt % 2 == 0) {
                            $tbcolor = "TableField2";
                        }
                        $c1 = $row["NAM_SX"];
                        echo "<tr><td class='" . $tbcolor . "'><b>$c1</b></td>";
                    }
                }
                ?>
    <table class='table table-condensed' width="1058" border="0">
              <tr>
                <th width="611" height="63" scope="col"><table class='table table-condensed' width="561" align="left"  border="0" cellpadding="0" cellspacing="1">
                    <tr class="TableField3">
                      <td colspan="3" class="TableHeader"><span>T&igrave;nh tr&#7841;ng </span></td>
                    </tr>
                    <tr class="TableField3">
                      <td width="153" class="TableHeader">Ngày</td>
                      <td width="168" class="TableHeader">Tình trạng </td>
                      <td width="218" class="TableHeader">Diễn giải </td>
                  </tr>
                    <tr>
                      <?php
                        $sql = "select * from chi_tiet_tt_may 
	where SO_N0='";
                        $sql.=$_GET['sono'] . "'";
                        $result = mysql_query($sql, $link);
                        $stt = 0;

                        if (mysql_num_rows($result) != 0)
                            while ($row = mysql_fetch_array($result)) {
                                $stt++;
                                $tbcolor = "TableField";
                                if ($stt % 2 == 0) {
                                    $tbcolor = "TableField2";
                                }
                                $c17 = $row["TINH_TRANG_NGAY"];
                                $c18 = $row["TEN_TINH_TRANG_MAY"];
                                $c19 = $row["DG_TINH_TRANG"];

                                echo "<tr><td width='153' class='" . $tbcolor . "'><b>$c17 </b></td>";
                                echo "<td width='164' class='" . $tbcolor . "'><b>$c18 </b></td>";
                                echo "<td width='218' class='" . $tbcolor . "'><b>$c19 </td></b></tr>";
                            } else {
                            echo "<tr><td colspan='3' class='" . $tbcolor . "'><b>N/A</b></td></tr>";
                        }
                        ?>
                    </tr>
                  </table></th>
                <th width="437" scope="col"><table class='table table-condensed' width="407" align="left" border="0" cellpadding="0" cellspacing="1">
                  <tr class="TableField3">
                    <td colspan="2" class="TableHeader" ><span>Lịch sử vận hành</span></td>
                  </tr>
                  <tr class="TableField3">
                    <td width="182" class="TableHeader">Ngày vận hành </td>
                    <td width="222" class="TableHeader">Trạm</td>
                    <?php
                                    $sql = "select * from mba_tram a, tram b
		where a.MA_TRAM=b.MA_TRAM and SO_N0='";
                                    $sql.=$_GET['sono'] . "'";
                                    $result = mysql_query($sql, $link);
                                    if (mysql_num_rows($result) != 0) {
                                        $stt = 0;
                                        while ($row = mysql_fetch_array($result)) {
                                            $stt++;
                                            $tbcolor = "TableField";
                                            if ($stt % 2 == 0) {
                                                $tbcolor = "TableField2";
                                            }
                                            $c1 = $row["NGAY_VAN_HANH"];
                                            $c2 = $row["TEN_TRAM"];

                                            echo "<tr><td class='" . $tbcolor . "'><b>$c1</b></td>";
                                            echo "<td class='" . $tbcolor . "'><b>$c2</b></td></tr>";
                                        }
                                    } else {
                                        echo "<tr><td colspan='2' class='" . $tbcolor . "'><b>N/A</b></td></tr>";
                                    }
                                    ?>
                  </tr>
                </table></th>
              </tr>
            </table>
            <p align="left">            
    <p align="left">
    <table class='table table-condensed' width="1058" border="0">
              <tr>
                <th width="609" scope="col"><table class='table table-condensed' width="163" border="0" cellpadding="0" cellspacing="1" align="left" >
                    <tr bgcolor="#FFFFFF" class="TableField3">
                      <td width="153" class="TableHeader"><span>Lịch sử đại tu</span></td>
                    </tr>
                    <tr bgcolor="#FFFFFF">
                      <td class="TableHeader">Ng&agrave;y</td>
                    </tr>
                    <?php
                    $sql = "select * from chi_tiet_dai_tu
	where SO_N0='";
                    $sql.=$_GET['sono'] . "'";
                    $result = mysql_query($sql, $link);
                    if (mysql_num_rows($result) != 0) {
                        $stt = 0;
                        while ($row = mysql_fetch_array($result)) {
                            $stt++;
                            $tbcolor = "TableField";
                            if ($stt % 2 == 0) {
                                $tbcolor = "TableField2";
                            }
                            $c1 = $row["NGAY_DAI_TU"];

                            echo "<tr><td class='" . $tbcolor . "'><b>$c1</b></td></tr>";
                        }
                    } else {
                        echo "<tr><td class='" . $tbcolor . "'><b>N/A</b></td></tr>";
                    }
                    ?>
                  </table></th>
                <th width="433" scope="col"><table class='table table-condensed' width="194" border="0" cellpadding="0" cellspacing="1" align="left">
                  <tr class="TableField3">
                    <td width="184" class="TableHeader"><span>Lịch sử ngừng vận hành</span></td>
                  </tr>
                  <tr>
                    <td class="TableHeader">Ngày</td>
                    <?php
                                    $sql = "select * from chi_tiet_ngung_van_hanh
	where SO_N0='";
                                    $sql.=$_GET['sono'] . "'";
                                    $result = mysql_query($sql, $link);
                                    if (mysql_num_rows($result) != 0) {
                                        $stt = 0;
                                        while ($row = mysql_fetch_array($result)) {
                                            $stt++;
                                            $tbcolor = "TableField";
                                            if ($stt % 2 == 0) {
                                                $tbcolor = "TableField2";
                                            }
                                            $c1 = $row["NGAY_NGUNG_VH"];

                                            echo "<tr><td class='" . $tbcolor . "'><b>$c1</b></td></tr>";
                                        }
                                    } else {
                                        echo "<tr><td class='" . $tbcolor . "'><b>N/A</b></td></tr>";
                                    }
                                    ?>
                  </tr>
                </table></th>
              </tr>
    </table>
    <p>&nbsp;</p>
                <p align="left">&nbsp;</p>

                <table class='table table-condensed' width="401" border="0" cellpadding="0" cellspacing="1">
                    <tr class="TableField3">
                        <td colspan="2" class="TableHeader"><span>Chi tiết sở hữu </span></td>
                  </tr>
                    <tr class="TableField3">
                        <td width="150" class="TableHeader">Ngày</td>
                        <td width="235" class="TableHeader">Đơn vị </td>
                  </tr>
                    <?php
                    $sql = "select * from chi_tiet_so_huu a, don_vi b where a.MA_DON_VI=b.MA_DON_VI and SO_N0='" . $_GET['sono'] . "'";
                    $result = mysql_query($sql, $link);

                    if (mysql_num_rows($result) != 0) {
                        $stt = 0;
                        while ($row = mysql_fetch_array($result)) {
                            $stt++;
                            $tbcolor = "TableField";
                            if ($stt % 2 == 0) {
                                $tbcolor = "TableField2";
                            }
                            $c1 = $row["NGAY_CHUYEN_DEN"];
                            $c2 = $row["TEN_DON_VI"];
                            echo "<tr><td class='" . $tbcolor . "'><b>$c1</b></td>";
                            echo "<td class='" . $tbcolor . "'><b>$c2</td></b></tr>";
                        }
                    } else {
                        echo "<tr><td colspan='2' class='" . $tbcolor . "'><b>N/A</b></td></tr>";
                    }
                    ?>
    </table>
               
                    <p align="center">&nbsp;</p>
                    <p align="right">
    <td width='600' align ='right'><input  type='submit' name='inexceltno' id='button' value='Xuất ra File Excel'></td>
                    		
					</p>
			
                    <p>                        
                    </p>
       
</body>
                </html>
